load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")

oncall("source_control")

# Due to some tools changing '-' to '_' when building,
# this library/crate is named using an '_' so that it can link successfully.
rust_library(
    name = "edenfs_ffi",
    srcs = glob(["src/**/*.rs"]),
    autocargo = {
        "cargo_target_config": {"crate_type": [
            "staticlib",
            "lib",
        ]},
        "cargo_toml_config": {
            "dependencies_override": {"build-dependencies": {"cxx-build": {"optional": False}}},
            "lib": {"name": "edenfs_ffi"},
            "package": {
                "authors": ["Meta Source Control Team <sourcecontrol-dev@meta.com>"],
                "homepage": "https://sapling-scm.com/",
                "license": "MIT",
                "name": "sapling-edenfs_ffi",
                "repository": "https://github.com/facebook/sapling",
            },
        },
    },
    cpp_deps = [":edenfs_ffi-wrapper"],
    crate_root = "src/lib.rs",
    cxx_bridge = "src/lib.rs",
    features = [
        "fb",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:cxx",
        "fbsource//third-party/rust:once_cell",
        "fbsource//third-party/rust:parking_lot",
        "fbsource//third-party/rust:tracing",
        "//eden/scm/lib/async-runtime:async-runtime",
        "//eden/scm/lib/config/model:configmodel",
        "//eden/scm/lib/filters:filters",
        "//eden/scm/lib/identity:identity",
        "//eden/scm/lib/metrics:metrics",
        "//eden/scm/lib/pathmatcher:pathmatcher",
        "//eden/scm/lib/repo:repo",
        "//eden/scm/lib/sparse:sparse",
        "//eden/scm/lib/types:types",
        "//eden/scm/lib/workingcopy:workingcopy",
    ],
)

cpp_library(
    name = "edenfs_ffi-wrapper",
    srcs = ["src/ffi.cpp"],
    headers = ["include/ffi.h"],
    preferred_linkage = "static",
    undefined_symbols = True,
    exported_deps = [
        "fbsource//third-party/rust:cxx-core",
        ":edenfs_ffi@header",  # @manual
        "//folly/futures:core",
    ],
)
